<template>
  <view>
    <view class="uni-com">
      <view class="mb50 flex_a h100 mt50 plr30 bf border-r1 shadow">
      	<view class="flex1"><input type="text" placeholder-class="c9" v-model="info.username" placeholder="请输入姓名" /></view>
      </view>
      <view class="mb50 flex_a h100 plr30 bf border-r1 shadow">
      	<view class="flex1"><input type="text" placeholder-class="c9" v-model="info.idCard" placeholder="请输入身份证" /></view>
      </view>
    </view>
    <view class="plr100 mt100 mb30">
    	<button class="btn-box" @click="putRz">下一步</button>
    </view>
  </view>
</template>

<script>
  import { getCertifyId } from '@/api/user.js'
  export default {
    data() {
      return {
        url:'',
        info:{},
      }
    },
    methods: {
      async putRz(){
        if(!this.info.username){
          uni.showToast({
            title: '请输入姓名',
            icon: 'none'
          })
          return
        }
        let id=/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/;
        if(!id.test(this.info.idCard)){
          uni.showToast({
            title: '请输入正确身份证号',
            icon: 'none'
          })
          return
        }
        let res = await getCertifyId(this.info)
        if(res.code === 200){
          let obj = {
            certifyId: res.data.certifyId,
            url: res.data.certifyUrl
          }
          my.call('startBizService', {
            name: 'open-certify',
            param: JSON.stringify(obj)
          }, (verifyResult) =>{
            console.log(verifyResult,'verifyResultverifyResultverifyResult')
            // 认证结果回调触发, 以下处理逻辑为示例代码，开发者可根据自身业务特性来自行处理
            if (verifyResult.resultStatus === '9000') {
              // 验证成功，接入方在此处处理后续的业务逻辑
              uni.reLaunch({
                url: '/pages/main/map'
              });
              return;
            }
            // 用户主动取消认证
            if (verifyResult.resultStatus === '6001') {
              // 可做下 toast 弱提示
              uni.showToast({
                title: '取消认证',
                icon: 'none'
              })
              return;
            }
            const errorCode = verifyResult.result && verifyResult.result.errorCode;
            // 其他结果状态码判断和处理 ...
            });
        }
      }
    }
  }
</script>
 
<style scoped>
  .uni-com{
    padding: 0 40rpx;
  }
  .btn-box{
    color: #fff;
    background-color: #3282FF;
    border-radius: 50rpx;
  }
</style>
